package com.ugtss.busniess.service.impl;

import com.ugtss.busniess.domain.EnterpriseInfo;
import com.ugtss.busniess.domain.dto.EnterpriseDto;
import com.ugtss.busniess.mapper.EnterpriseMapper;
import com.ugtss.busniess.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional(rollbackFor = Exception.class)
@Service
public class EnterpriseServiceImpl implements EnterpriseService {

    @Autowired
    private EnterpriseMapper enterpriseMapper;

    @Override
    public List<EnterpriseInfo> getList() {
        return enterpriseMapper.getList();
    }

    @Override
    public List<EnterpriseInfo> getListByParams(EnterpriseDto dto) {
        List<EnterpriseInfo> list = enterpriseMapper.getListByParams(dto);
        return list;
    }

    @Override
    public void add(EnterpriseDto dto) {
        try {
            enterpriseMapper.add(dto);
        } catch (Exception e) {
            throw new RuntimeException("新增失败");
        }


    }

    @Override
    public void delete(Integer id) {
        try {
            enterpriseMapper.delete(id);
        } catch (Exception e) {
            throw new RuntimeException("删除失败");
        }
    }

    @Override
    public void update(EnterpriseDto dto) {
        if (dto.getId() == null) {
            throw new IllegalArgumentException("企业 ID 不能为空！");
        }
        try {
            enterpriseMapper.update(dto);
        } catch (Exception e) {
            throw new RuntimeException("修改失败");
        }
    }

    @Override
    public EnterpriseInfo getOwnInfo(Integer userId) {
        return enterpriseMapper.getOwnInfo(userId);
    }

}
